home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / xvidiff.zip / DEFSCR.C next >
C/C++ Source or Header  |  1993-01-01  |  6KB  |  328 lines

  1. /* Copyright (c) 1990,1991,1992 Chris and John Downey */
  2. #ifndef lint
  3. static char *sccsid = "@(#)defscr.c    2.4 (Chris & John Downey) 9/4/92";
  4. #endif
  5.  
  6. /***
  7.  
  8. * program name:
  9.     xvi
  10. * function:
  11.     PD version of UNIX "vi" editor, with extensions.
  12. * module name:
  13.     defscr.c
  14. * module function:
  15.     VirtScr interface using old style porting functions.
  16.     We assume newscr() is only called once; it is an
  17.     error for it to be called more than once.
  18. * history:
  19.     STEVIE - ST Editor for VI Enthusiasts, Version 3.10
  20.     Originally by Tim Thompson (twitch!tjt)
  21.     Extensive modifications by Tony Andrews (onecom!wldrdg!tony)
  22.     Heavily modified by Chris & John Downey
  23.  
  24. ***/
  25.  
  26. #include "xvi.h"
  27.  
  28. static    VirtScr    *newscr P((VirtScr *));
  29. static    void    closescr P((VirtScr *));
  30. static    int    getrows P((VirtScr *));
  31. static    int    getcols P((VirtScr *));
  32. static    void    clear_all P((VirtScr *));
  33. static    void    clear_line P((VirtScr *, int, int));
  34. static    void    xygoto P((VirtScr *, int, int));
  35. static    void    xyadvise P((VirtScr *, int, int, int, char *));
  36. static    void    put_char P((VirtScr *, int, int, int));
  37. static    void    put_str P((VirtScr *, int, int, char *));
  38. static    void    ins_str P((VirtScr *, int, int, char *));
  39. static    void    pset_colour P((VirtScr *, int));
  40. static    int    colour_cost P((VirtScr *));
  41. static    int    scroll P((VirtScr *, int, int, int));
  42. static    void    flushout P((VirtScr *));
  43. static    void    pbeep P((VirtScr *));
  44.  
  45. VirtScr    defscr = {
  46.     NULL,        /* pv_window        */
  47.     0,            /* pv_rows        */
  48.     0,            /* pv_cols        */
  49.  
  50.     newscr,        /* v_new        */
  51.     closescr,        /* v_close        */
  52.     getrows,        /* v_rows        */
  53.     getcols,        /* v_cols        */
  54.     clear_all,        /* v_clear_all        */
  55.     clear_line,        /* v_clear_line        */
  56.     xygoto,        /* v_goto        */
  57.     xyadvise,        /* v_advise        */
  58.     put_str,        /* v_write        */
  59.     put_char,        /* v_putc        */
  60.     pset_colour,    /* v_set_colour        */
  61.     colour_cost,    /* v_colour_cost    */
  62.     flushout,        /* v_flush        */
  63.     pbeep,        /* v_beep        */
  64.  
  65.     ins_str,        /* v_insert        */
  66.     scroll,        /* v_scroll        */
  67.     NULL,        /* v_flash        */
  68.     NULL,        /* v_status        */
  69.     NULL,        /* v_activate        */
  70. };
  71.  
  72. int
  73. main(argc, argv)
  74. int    argc;
  75. char    *argv[];
  76. {
  77.     xvEvent    event;
  78.     long    timeout = 0;
  79.  
  80.     /*
  81.      * Set up the system and terminal interfaces. This establishes
  82.      * the window size, changes to raw mode and does whatever else
  83.      * is needed for the system we're running on.
  84.      */
  85.     sys_init();
  86.  
  87.     if (!can_inschar) {
  88.     defscr.v_insert = NULL;
  89.     }
  90.     if (!can_scroll_area && !can_ins_line && !can_del_line) {
  91.     defscr.v_scroll = NULL;
  92.     }
  93.     defscr.pv_rows = Rows;
  94.     defscr.pv_cols = Columns;
  95.  
  96.     defscr.pv_window = (genptr *) xvi_startup(&defscr, argc, argv,
  97.                             getenv("XVINIT"));
  98.  
  99.     while (1) {
  100.     register int    r;
  101.  
  102.     r = inchar(timeout);
  103.     if (r == EOF) {
  104.         event.ev_type = Ev_timeout;
  105.     } else {
  106.         event.ev_type = Ev_char;
  107.         event.ev_inchar = r;
  108.     }
  109.     timeout = xvi_handle_event(&event);
  110.     }
  111.     return 0;
  112. }
  113.  
  114. /*ARGSUSED*/
  115. static VirtScr *
  116. newscr(scr)
  117. VirtScr    *scr;
  118. {
  119.     return(NULL);
  120. }
  121.  
  122. /*ARGSUSED*/
  123. static void
  124. closescr(scr)
  125. VirtScr    *scr;
  126. {
  127. }
  128.  
  129. /*ARGSUSED*/
  130. static int
  131. getrows(scr)
  132. VirtScr    *scr;
  133. {
  134.     return(scr->pv_rows);
  135. }
  136.  
  137. /*ARGSUSED*/
  138. static int
  139. getcols(scr)
  140. VirtScr    *scr;
  141. {
  142.     return(scr->pv_cols);
  143. }
  144.  
  145. /*ARGSUSED*/
  146. static void
  147. clear_all(scr)
  148. VirtScr    *scr;
  149. {
  150.     erase_display();
  151. }
  152.  
  153. /*ARGSUSED*/
  154. static void
  155. clear_line(scr, row, col)
  156. VirtScr    *scr;
  157. int    row;
  158. int    col;
  159. {
  160.     tty_goto(row, col);
  161.     erase_line();
  162. }
  163.  
  164. /*ARGSUSED*/
  165. static void
  166. xygoto(scr, row, col)
  167. VirtScr    *scr;
  168. int    row;
  169. int    col;
  170. {
  171.     tty_goto(row, col);
  172. }
  173.  
  174. /*ARGSUSED*/
  175. static void
  176. xyadvise(scr, row, col, index, str)
  177. VirtScr    *scr;
  178. int    row;
  179. int    col;
  180. int    index;
  181. char    *str;
  182. {
  183.     if (index > cost_goto) {
  184.     tty_goto(row, col + index);
  185.     } else {
  186.     tty_goto(row, col);
  187.     while (--index > 0) {
  188.         outchar(*str++);
  189.     }
  190.     }
  191. }
  192.  
  193. /*ARGSUSED*/
  194. static void
  195. put_str(scr, row, col, str)
  196. VirtScr    *scr;
  197. int    row;
  198. int    col;
  199. char    *str;
  200. {
  201.     tty_goto(row, col);
  202.     outstr(str);
  203. }
  204.  
  205. /*ARGSUSED*/
  206. static void
  207. put_char(scr, row, col, c)
  208. VirtScr    *scr;
  209. int    row;
  210. int    col;
  211. int    c;
  212. {
  213.     tty_goto(row, col);
  214.     outchar(c);
  215. }
  216.  
  217. /*ARGSUSED*/
  218. static void
  219. ins_str(scr, row, col, str)
  220. VirtScr    *scr;
  221. int    row;
  222. int    col;
  223. char    *str;
  224. {
  225.     /*
  226.      * If we are called, can_inschar is TRUE,
  227.      * so we know it is safe to use inschar().
  228.      */
  229.     tty_goto(row, col);
  230.     for ( ; *str != '\0'; str++) {
  231.     inschar(*str);
  232.     }
  233. }
  234.  
  235. /*ARGSUSED*/
  236. static void
  237. pset_colour(scr, colour)
  238. VirtScr    *scr;
  239. int    colour;
  240. {
  241.     set_colour(colour);
  242. }
  243.  
  244. /*ARGSUSED*/
  245. static int
  246. colour_cost(scr)
  247. VirtScr    *scr;
  248. {
  249. #ifdef    SLINE_GLITCH
  250.     return(SLINE_GLITCH);
  251. #else
  252.     return(0);
  253. #endif
  254. }
  255.  
  256. /*ARGSUSED*/
  257. static int
  258. scroll(scr, start_row, end_row, nlines)
  259. VirtScr    *scr;
  260. int    start_row;
  261. int    end_row;
  262. int    nlines;
  263. {
  264.     if (nlines < 0) {
  265.     /*
  266.      * nlines negative means scroll reverse - i.e. move
  267.      * the text downwards with respect to the terminal.
  268.      */
  269.     nlines = -nlines;
  270.  
  271.     if (can_scroll_area) {
  272.         scroll_down(start_row, end_row, nlines);
  273.     } else if (can_ins_line && end_row == Rows - 1) {
  274.         int    line;
  275.  
  276.         for (line = 0; line < nlines; line++) {
  277.         tty_goto(start_row, 0);
  278.         insert_line();
  279.         }
  280.     } else {
  281.         return(0);
  282.     }
  283.     } else if (nlines > 0) {
  284.     /*
  285.      * Whereas nlines positive is "normal" scrolling.
  286.      */
  287.     if (can_scroll_area) {
  288.         scroll_up(start_row, end_row, nlines);
  289.     } else if (end_row == Rows - 1) {
  290.         int    line;
  291.  
  292.         if (can_del_line) {
  293.         for (line = 0; line < nlines; line++) {
  294.             tty_goto(start_row, 0);
  295.             delete_line();
  296.         }
  297.         } else if (start_row == 0) {
  298.         tty_goto(start_row, 0);
  299.         for (line = 0; line < nlines; line++) {
  300.             delete_line();
  301.         }
  302.         } else {
  303.         return(0);
  304.         }
  305.     } else {
  306.         return(0);
  307.     }
  308.     }
  309.     return(1);
  310. }
  311.  
  312. /*ARGSUSED*/
  313. static void
  314. flushout(scr)
  315. VirtScr    *scr;
  316. {
  317.     flush_output();
  318. }
  319.  
  320. /*ARGSUSED*/
  321. static void
  322. pbeep(scr)
  323. VirtScr    *scr;
  324. {
  325.     alert();
  326.     flush_output();
  327. }
  328.